package com.lin.videospringboot.config;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;

import javax.servlet.http.HttpServletRequest;
import java.nio.file.Path;

@Component
public class ResourceHandler extends ResourceHttpRequestHandler {

    public final static String FILE_ATTR = "NON-STATIC-FILE";

    @Override
    protected Resource getResource(HttpServletRequest request) {
        final Path path = (Path) request.getAttribute(FILE_ATTR);
        return new FileSystemResource(path);
    }
}
